package news.web;

import news.model.Admin;
import news.model.CommonResult;
import news.model.Menu;
import news.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path = "/admin/login")
public class LoginController {

    @Autowired
    LoginService loginService;


    @PostMapping(path = "/login")
    public CommonResult login(@RequestBody Admin admin){
        CommonResult commonResult = loginService.login(admin);
        return commonResult;
    }

    @GetMapping(path = "/menus")
    public CommonResult menus(@RequestHeader("adminToken") String adminToken){
        List<Menu> menus = loginService.menus(adminToken);
        CommonResult commonResult = new CommonResult(200,menus,"查询成功");
        return commonResult;
    }
}
